﻿<%@ Page EnableEventValidation="false" validateRequest="false" Title="" Language="C#" MasterPageFile="~/MasterPage/Site.Master" AutoEventWireup="true" CodeBehind="EditStage.aspx.cs" Inherits="BEELab.EditStage" %>
<%@ Import Namespace="System.Data" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script> var blocks = [  <asp:Literal ID="BlocksLiteral" runat="server"></asp:Literal> ];  
             <asp:Literal ID="BlocksEnumerationLiteral" runat="server"></asp:Literal>
             
             var editors = new Array();     

             var savingCounter = 0;

             function UpdateSaving(d)
             {
                 savingCounter += d;

                 if (savingCounter == 0)
                 {
                     $('#SavingSpan').hide();
                 }
                 else
                 {
                     $('#SavingSpan').show();
                 }
             }
    </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentBody" runat="server">
    <asp:ScriptManager runat="server" >

    </asp:ScriptManager>
    
    <script src="./Scripts/codemirror-3.01/codemirror.js"></script>
    <link rel="stylesheet" href="./Content/codemirror-3.01/codemirror.css"/>
    <script src="./Scripts/codemirror-3.01/mode/javascript.js"></script>

    <script src="./Scripts/codemirror-3.0/addon/edit/matchbrackets.js"></script>

    <style type="text/css">
      .CodeMirror {
        border: 1px solid #9b9b9b;
        height: auto;
        min-height: 100px;
        width: 730px;
      }
      .CodeMirror-scroll {
        overflow-y: hidden;
        overflow-x: auto;
      }
      div.CodeMirror span.CodeMirror-matchingbracket {
        color: blue;
        font-weight: bold;
      }
      div.CodeMirror span.CodeMirror-nonmatchingbracket {
        color: red;
        font-weight: bold;
      }
    </style>

    <div id="wrap" class="clearfix">
        <asp:Label ID="lblEdit" runat="server" Visible="true"> <a id="btnBack" runat="server" class="back-btn" href="#" onserverclick="Back_Click">Back</a> <h2 class="headline">Edit Stage</h2></asp:Label>
            <div class="block" id="DivStageInfo" runat="server">

            <h3>Stage Information</h3>

            <asp:UpdatePanel ID="UpdatePanel4" runat="server" UpdateMode="Always">
                <ContentTemplate>
                    <div class="sign-form">
                        <div class="input-hold">
                            <asp:Label ID="Label1" CssClass="sign-label" AssociatedControlID="txtName" runat="server">Name</asp:Label>
                            <asp:TextBox CssClass="sign-input" ID="txtName" runat="server" Width="300px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvtxtName" ValidationGroup="StageGroup" ControlToValidate="txtName" ForeColor="Red" Text="*" runat="server" Display="Dynamic" ErrorMessage="* Name is required"></asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ValidationExpression=".*" EnableClientScript="True" ID="StageRegularExpressionValidator" ForeColor="Red" ValidationGroup="StageGroup" ControlToValidate="txtName" runat="server" ErrorMessage="* Name already in use"></asp:RegularExpressionValidator>
                        </div>

                        <div class="input-hold">
                            <asp:Label ID="Label2" CssClass="sign-label" AssociatedControlID="txtDescription" runat="server">Description</asp:Label>
                            <asp:TextBox ID="txtDescription" CssClass="text-area" runat="server" TextMode="MultiLine"></asp:TextBox>

                            <asp:RequiredFieldValidator ID="rfvtxtDescription" ValidationGroup="StageGroup" ForeColor="Red" Text="*" ControlToValidate="txtDescription" runat="server" ErrorMessage="* Description is required."></asp:RequiredFieldValidator>
                        </div>

                        <div class="input-hold">
                            <asp:Button CssClass="sign-submit" ValidationGroup="StageGroup" ID="btnSubmit" Text="Submit" runat="server" OnClick="btnSubmit_Click" />
                        </div>
                    </div>
                    <div class="error">
                        <asp:ValidationSummary ID="vsStage" runat="server" ValidationGroup="StageGroup" />
                        <p>&nbsp</p>
                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>

        <br />

        <div class="block" id="DivPresentationLayer" runat="server">
            <div class="dashboard-hold">
                <h3>Presentation Layer</h3>
                
                <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Always">
                    <ContentTemplate>
                        <div class="sign-form">
                            <div class="editor">
                                <asp:TextBox ID="PresentationLayertxtContent" CssClass="tiny-content" runat="server" TextMode="MultiLine" Style="width: 80%; min-height: 230px; resize: none;">Your Content Here</asp:TextBox>
                            </div>

                            <div class="input-hold">
                                <asp:Button ID="btnContent" CssClass="sign-submit" Text="Submit" runat="server" OnClick="btnContent_Click" OnClientClick="tinyMCE.triggerSave();" />
                            </div>
                        </div>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
        </div>

        <br />

        <div class="block" id="DivPresentationElements" runat="server">
            <div class="dashboard-hold">
                <h3>Presentation Layer Elements</h3>

                <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource6" CssClass="dash-col" OnRowDeleting="GridView2_RowDeleting">
                    <Columns>
                        <asp:BoundField DataField="Name" HeaderText="Name"  />
                        <asp:BoundField DataField="Description" HeaderText="Description" />
                        <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="EditPresentationElement.aspx?ID={0}" Text="Edit" />
                        <asp:ButtonField CommandName="Delete" Text="Delete" />
                    </Columns>
                </asp:GridView>
                <asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:beelabConnectionString %>" SelectCommand="SELECT ID, Name, Description FROM PresentationElements WHERE StageID=@StageID AND Name!=('PresentationLayer' + @StageIDSTR)" DeleteCommand="DELETE FROM PresentationElements WHERE ID=@ID">
                    <SelectParameters>
                        <asp:QueryStringParameter Name="StageID" QueryStringField="ID" Type="Int32" />
                        <asp:QueryStringParameter Name="StageIDSTR" QueryStringField="ID" Type="String" />
                    </SelectParameters>
                    <DeleteParameters>
                        <asp:ControlParameter ControlID="GridView2" Type="Int32" />
                    </DeleteParameters>
                </asp:SqlDataSource>

                <a href="EditPresentationElement.aspx?StageID=<% Response.Write(Request.QueryString["ID"]); %>" id="newPresentationItem" class="abbtn fancybox">New Presentation Element</a><br />
            </div>
        </div>
        
        <br />
        
        <div class="block" id="DivVariables" runat="server">
            <div class="dashboard-hold">
                <h3>Variable List</h3>

                <a href="#new-experimentvariable" id="newVariable" class="abbtn fancybox">New Variable</a>
                <div id="new-experimentvariable" style="width: 640px; padding: 24px; border: 1px solid #ddd; display: none">
                    
                    <h2 class="headline" id="new-variable">New Variable</h2>

                    <div class="sign-form">

                        <div class="input-hold">
                            <asp:Label ID="Label15" CssClass="sign-label" AssociatedControlID="TextBox3" runat="server">Name</asp:Label>
                            <asp:TextBox CssClass="sign-input" ID="TextBox3" runat="server" Width="200px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator8" ForeColor="Red" ValidationGroup="VariableGroup" ControlToValidate="TextBox3" runat="server" ErrorMessage="* Name is required" Text="*"></asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ValidationExpression="[a-zA-Z][_a-zA-Z0-9]*" EnableClientScript="True" ID="RegexValidator1" ForeColor="Red" ValidationGroup="VariableGroup" ControlToValidate="TextBox3" runat="server" ErrorMessage="* Name must be a valid JS variable name"></asp:RegularExpressionValidator>
                            <asp:RegularExpressionValidator ValidationExpression=".*" EnableClientScript="True" ID="RegexValidator2" ForeColor="Red" ValidationGroup="VariableGroup" ControlToValidate="TextBox3" runat="server" ErrorMessage="* Name already in use"></asp:RegularExpressionValidator>
                        </div>

                        <div class="input-hold">
                            <asp:Label ID="Label16" CssClass="sign-label" AssociatedControlID="TextBox4" runat="server">Description</asp:Label>
                            <asp:TextBox CssClass="text-area" ID="TextBox4" runat="server" TextMode="MultiLine"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator9" ForeColor="Red" ValidationGroup="VariableGroup" ControlToValidate="TextBox4" runat="server" ErrorMessage="* Description is required" Text="*"></asp:RequiredFieldValidator>
                        </div>

                        <div class="input-hold">
                            <asp:Label ID="Label17" CssClass="sign-label1" AssociatedControlID="txtDefaultValue" runat="server">Default Value <br /><span>String values must be enclosed by double quotation marks</span></asp:Label>
                            <asp:TextBox ID="txtDefaultValue" CssClass="sign-input" runat="server"></asp:TextBox>
                        </div>

                        <div class="input-hold">
                            <asp:Label ID="Label18" CssClass="sign-label" AssociatedControlID="rblScope" runat="server">Scope</asp:Label>
                            <asp:RadioButtonList CssClass="sign-radio list-space" runat="server" ID="rblScope" RepeatDirection="Horizontal">
                                <asp:ListItem Text="Session" Value="Session"></asp:ListItem>
                                <asp:ListItem Text="Subject" Value="Subject"></asp:ListItem>
                            </asp:RadioButtonList>

                            <asp:RequiredFieldValidator ID="rfvddlScope" ForeColor="Red" ValidationGroup="VariableGroup" ControlToValidate="rblScope" runat="server" ErrorMessage="* Scope is required." InitialValue="Selecet Scope" Display="Dynamic" Text="*"></asp:RequiredFieldValidator>
                        </div>

                        <div class="input-hold">
                            <asp:Button CssClass="sign-submit" ID="Button4" Text="Submit" runat="server" ValidationGroup="VariableGroup" OnClick="Button4_Click" />
                        </div>
                    </div>
                    <div class="error">
                        <p>&nbsp</p>
                    </div>

                </div>

                <asp:GridView ID="gvVariable" DataKeyNames="ID" runat="server" AutoGenerateColumns="False" CssClass="dash-col" DataSourceID="SqlDataSource7" OnRowDeleting="gvVariable_RowDeleting">
                    <Columns>
                        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" Visible="False" />
                        <asp:BoundField DataField="ProgramID" HeaderText="ProgramID" SortExpression="ProgramID" Visible="False" />
                        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                        <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="EditVariable.aspx?ID={0}" Text="Edit" />
                        <asp:CommandField ShowDeleteButton="True" ShowHeader="True" />
                    </Columns>
                </asp:GridView>
                <asp:SqlDataSource ID="SqlDataSource7" runat="server" ConnectionString="<%$ ConnectionStrings:beelabConnectionString %>" DeleteCommand="DELETE FROM Variables WHERE ID=@ID" SelectCommand="SELECT [ID], [ProgramID], [Name], [Description] FROM [Variables] WHERE ([ProgramID] = (SELECT ProgramID FROM Stages WHERE ID=@StageID))">
                    <DeleteParameters>
                        <asp:ControlParameter ControlID="gvVariable" Name="ID" PropertyName="SelectedValue" />
                    </DeleteParameters>
                    <SelectParameters>
                        <asp:QueryStringParameter Name="StageID" QueryStringField="ID" Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </div>
        </div>

        <br />

        <div class="block" id="DivLogicLayer" runat="server">
            <div class="dashboard-hold">
                <h3>Logic Layer</h3> <span id="SavingSpan">(Saving...)</span>
                <div class="logic-tab">
                            
                    <% if (Request.QueryString["NoFunctions"] == null || Request.QueryString["NoFunctions"].ToString().Equals("true") == false ){%>
                    
                    <div id="list-function" style="width: 640px; padding: 24px; border: 1px solid #ddd; display: none;">
                        <h2 class="headline">Remove / Set Functions</h2>
                        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource4" CssClass="dash-col" OnRowDeleting="GridView1_RowDeleting">
                            <Columns>
                                <asp:BoundField DataField="Name" HeaderText="Instance Name" SortExpression="Name" />
                                <asp:BoundField DataField="Type" HeaderText="Function Type" SortExpression="Type" />
                                <asp:HyperLinkField DataNavigateUrlFields="ID, FunctionID" DataNavigateUrlFormatString="FunctionSettings.aspx?ID={0}&FunctionID={1}" Text="Settings" />
                                <asp:ButtonField CommandName="Delete" Text="Remove" />
                            </Columns>
                        </asp:GridView>
                        <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:beelabConnectionString %>" SelectCommand="SELECT * FROM [Containers] WHERE ([StageID] = @StageID)" DeleteCommand="DELETE FROM Containers WHERE ID=@Param1; DELETE FROM Programs WHERE Type='Function' AND isVisible='false' AND NOT EXISTS (SELECT ID FROM Containers WHERE FunctionID=Programs.ID)">
                            <DeleteParameters>
                                <asp:ControlParameter ControlID="GridView1" Name="Param1" PropertyName="SelectedValue" />
                            </DeleteParameters>
                            <SelectParameters>
                                <asp:QueryStringParameter Name="StageID" QueryStringField="ID" Type="Int32" />
                            </SelectParameters>
                        </asp:SqlDataSource>

                        <div class="spacer"></div>

                        <h2 class="headline">Add Function</h2>

                        <div class="sign-form">
                            <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true">
                                <ContentTemplate>
                                    <div class="input-hold">
                                        <asp:Label ID="Label12" CssClass="sign-label" runat="server" AssociatedControlID="ddlFunction" Text="Function"></asp:Label>
                                        <asp:DropDownList CssClass="sign-select" ID="ddlFunction" runat="server" DataSourceID="SqlDataSource2" DataTextField="Name" DataValueField="ID" AutoPostBack="false">
                                        </asp:DropDownList>
                                        <asp:RequiredFieldValidator ID="rfvddlFunction" ControlToValidate="ddlFunction" InitialValue="Choose" ForeColor="Red" ValidationGroup="FunctionGroup" runat="server" ErrorMessage="* Function is required" Text="*"></asp:RequiredFieldValidator>
                                        <asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:beelabConnectionString %>" SelectCommand="SELECT ID, Name, Description FROM Programs WHERE (OwnerID=@OwnerID OR Permission='Public') AND Type='Function' AND isVisible='true';" runat="server">
                                            <SelectParameters>
                                                <asp:SessionParameter Name="OwnerID" SessionField="UserID" Type="Int32" />
                                            </SelectParameters>
                                        </asp:SqlDataSource>
                                    </div>
                                    <div class="input-hold">
                                        <asp:Label ID="Label13" CssClass="sign-label" runat="server" AssociatedControlID="txtFuncDesc" Text="Description"></asp:Label>
                                        <asp:Label ID="txtFuncDesc" runat="server" CssClass="sign-label"></asp:Label>
                                    </div>

                                    <div class="input-hold">
                                        <asp:Label ID="Label14" CssClass="sign-label" AssociatedControlID="txtIntanceName" runat="server">Instance Name</asp:Label>
                                
                                                <asp:TextBox CssClass="sign-input name" ID="txtIntanceName" runat="server" Width="200px"></asp:TextBox>
                                    
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator7" ForeColor="Red" Text="*" ValidationGroup="FunctionGroup" ControlToValidate="txtIntanceName" runat="server" ErrorMessage="* Instance Name is required."></asp:RequiredFieldValidator>
                                        <asp:RegularExpressionValidator ValidationExpression="[_a-zA-Z][_a-zA-Z0-9]*" EnableClientScript="True" ID="RegularExpressionValidator123" ForeColor="Red" ValidationGroup="FunctionGroup" ControlToValidate="txtIntanceName" runat="server" ErrorMessage="* Instance name must be a valid JS function name"></asp:RegularExpressionValidator>
                                        <asp:RegularExpressionValidator ValidationExpression=".*" EnableClientScript="True" ID="InstanceRegexValidator" ForeColor="Red" ValidationGroup="FunctionGroup" ControlToValidate="txtIntanceName" runat="server" ErrorMessage="Instance name already in use in this experiment / function. Please enter a unique instance name and try again"></asp:RegularExpressionValidator>
                                    </div>
                                </ContentTemplate>
                            </asp:UpdatePanel>

                            <div class="input-hold">
                                <asp:Button ID="AddFunctionSubmit" runat="server" Text="Submit" CssClass="sign-submit" ValidationGroup="FunctionGroup" OnClick="AddFunctionSubmit_Click" OnClientClick="if (Page_ClientValidate('FunctionGroup')) { $.fancybox.open({'content':'Please Wait...'}); }" />
                            </div>
                        </div>
                        
                        <div class="clr"></div>
                        <div class="error">
                            <asp:ValidationSummary ValidationGroup="FunctionGroup" ID="vsFunction" runat="server" />
                            <p></p>
                        </div>
                    </div>

                    <a href="#list-function" class="logicbtn fancybox">Functions</a>

                    <% } %>

                    <a href="#new-block" class="logicbtn fancybox">add new block</a>
                    <div id="new-block" style="width: 640px; padding: 24px; border: 1px solid #ddd; display:none">
                                
                        <h2 class="headline">Add New Block</h2>
                        <div class="sign-form">
                            <div class="input-hold">
                                <asp:Label ID="Label3" CssClass="sign-label" AssociatedControlID="NewBlockName" runat="server">Name</asp:Label>
                                <asp:TextBox CssClass="sign-input name" ID="NewBlockName" runat="server" Width="200px"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ForeColor="Red" Text="*" ValidationGroup="BlockGroup" ControlToValidate="NewBlockName" runat="server" ErrorMessage="* Name is required."></asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator ValidationExpression="[_a-zA-Z][_a-zA-Z0-9]*" EnableClientScript="True" ID="RegularExpressionValidator1" ForeColor="Red" ValidationGroup="BlockGroup" ControlToValidate="NewBlockName" runat="server" ErrorMessage="* Name must be a valid JS function name"></asp:RegularExpressionValidator>
                                <asp:RegularExpressionValidator ValidationExpression=".*" EnableClientScript="True" ID="RegularExpressionValidator3" ForeColor="Red" ValidationGroup="BlockGroup" ControlToValidate="NewBlockName" runat="server" ErrorMessage="* Name already in use"></asp:RegularExpressionValidator>
                            </div>

                            <div class="input-hold">
                                <asp:Label ID="Label4" CssClass="sign-label" AssociatedControlID="NewBlockDescription" runat="server">Description</asp:Label>
                                <asp:TextBox CssClass="text-area description" ID="NewBlockDescription" runat="server" TextMode="MultiLine"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ForeColor="Red" Text="*" ValidationGroup="BlockGroup" ControlToValidate="NewBlockDescription" runat="server" ErrorMessage="* Description is required."></asp:RequiredFieldValidator>
                            </div>

                            <div class="input-hold">
                                <asp:Label ID="Label19" CssClass="sign-label" AssociatedControlID="AddCodeCheckBox" runat="server">Add Empty Code Inside</asp:Label>
                                <asp:CheckBox CssClass="sign-checkbox" ID="AddCodeCheckBox" runat="server" />
                            </div>

                            <div class="input-hold">
                                <asp:Button CssClass="sign-submit save" data-type="block" ID="Button1" Text="Submit" ValidationGroup="BlockGroup" runat="server" OnClick="Button1_Click" />
                            </div>
                        </div>
                        <div class="error">
                            <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="BlockGroup" />
                            <p>&nbsp</p>
                        </div>

                    </div>

                    <a href="#new-call" class="logicbtn fancybox">add new call</a>
                    <div id="new-call" style="width: 640px; padding: 24px; border: 1px solid #ddd; display: none;">
                                
                        <h2 class="headline">Add New Call</h2>
                        <div class="sign-form">
                            <div class="input-hold">
                                <asp:Label ID="Label5" CssClass="sign-label" AssociatedControlID="NewCallName" runat="server">Name</asp:Label>
                                <asp:TextBox CssClass="sign-input name" ID="NewCallName" runat="server" Width="200px"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" CssClass="field-validation-error" ControlToValidate="NewCallName" ValidationGroup="CallGroup" runat="server" ErrorMessage="* Name is required." Text="*"></asp:RequiredFieldValidator>
                            </div>

                            <div class="input-hold">
                                <asp:Label ID="Label6" CssClass="sign-label" AssociatedControlID="NewCallDescription" runat="server">Description</asp:Label>
                                <asp:TextBox CssClass="text-area description" ID="NewCallDescription" runat="server" TextMode="MultiLine"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" Display="Dynamic" ControlToValidate="NewCallDescription" ValidationGroup="CallGroup" runat="server" ErrorMessage="* Description is required" Text="*"></asp:RequiredFieldValidator>
                            </div>

                            <div class="input-hold">
                                <asp:Label ID="Label7" CssClass="sign-label" runat="server" AssociatedControlID="NewCallContent" Text="Call Target"></asp:Label>
                                <asp:DropDownList CssClass="sign-select callValue" ID="NewCallContent" DataSourceID="SqlDataSource3" DataTextField="Name" DataValueField="ID" runat="server">
                                </asp:DropDownList>
                                <asp:SqlDataSource ID="SqlDataSource3" ConnectionString="<%$ ConnectionStrings:beelabConnectionString %>" SelectCommand="SELECT ID, Name FROM BlockElements WHERE StageID=@StageID AND Type='Block';" runat="server">
                                    <SelectParameters>
                                        <asp:QueryStringParameter Name="StageID" QueryStringField="ID" Type="Int32" />
                                    </SelectParameters>
                                </asp:SqlDataSource>
                            </div>
                            <div class="input-hold">
                                <asp:Button CssClass="sign-submit save" data-type="call" ID="Button2" runat="server" Text="Submit" OnClick="Button2_Click" ValidationGroup="CallGroup"/>
                            </div>
                        </div>
                        <div class="error">
                            <asp:ValidationSummary ID="ValidationSummary3" runat="server" ValidationGroup="CallGroup" />
                            <p>&nbsp</p>
                        </div>

                    </div>

                    <a href="#new-code" class="logicbtn fancybox">add new code</a>
                    <div id="new-code" style="width: 640px; padding: 24px; border: 1px solid #ddd; display: none;">
                                
                        <h2 class="headline">Add New Code</h2>
                        <div class="sign-form">
                            <div class="input-hold">
                                <asp:Label ID="Label8" CssClass="sign-label" AssociatedControlID="NewCodeName" runat="server">Name</asp:Label>
                                <asp:TextBox CssClass="sign-input name" ID="NewCodeName" runat="server" Width="200px"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" CssClass="field-validation-error" ControlToValidate="NewCodeName" ValidationGroup="CodeGroup" runat="server" ErrorMessage="* Name is required." Text="*"></asp:RequiredFieldValidator>
                            </div>

                            <div class="input-hold">
                                <asp:Label ID="Label9" CssClass="sign-label" AssociatedControlID="NewCodeDescription" runat="server">Description</asp:Label>
                                <asp:TextBox CssClass="text-area description" ID="NewCodeDescription" runat="server" TextMode="MultiLine"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" Display="Dynamic" ControlToValidate="NewCodeDescription" ValidationGroup="CodeGroup" runat="server" ErrorMessage="* Description is required" Text="*"></asp:RequiredFieldValidator>
                            </div>

                            <div class="input-hold">
                                <label class="sign-label1">
                                    Code<br>
                                    <span>(Optional)</span></label><asp:TextBox CssClass="text-area description" ID="NewCodeContent" runat="server" TextMode="MultiLine"></asp:TextBox>
                            </div>
                            <div class="input-hold">
                                <asp:Button CssClass="sign-submit save" data-type="code" runat="server" Text="Submit" ID="Submit" OnClick="Submit_Click" ValidationGroup="CodeGroup"/>
                            </div>
                        </div>
                        <div class="error">
                            <asp:ValidationSummary ID="ValidationSummary4" runat="server" ValidationGroup="CodeGroup" />
                            <p>&nbsp</p>
                        </div>

                    </div>
                </div>

                <br />

                <asp:Repeater ID="rptLogicLayer" runat="server" OnItemDataBound="rptLogicLayer_ItemDataBound">
                            <HeaderTemplate>
                                <ol class="logic-box">
                            </HeaderTemplate>
                            <ItemTemplate>
                                <li id="list_item" runat="server">
                                    <div id="logicblock" class="logicblock" runat="server">
                                        <asp:HiddenField ID="hfCCID" runat="server" />
                                        <!-- header -->
                                        <div class="headblock clearfix" id="hblock" runat="server">
                                            <div class="headlinehold">
                                                <div class="text">
                                                    <h2 class="inplace-edit">
                                                        <asp:Literal ID="ltlBlockName" runat="server" />
                                                        <span>(<asp:Literal ID="ltlDataType" runat="server" />)</span></h2>
                                                    <asp:PlaceHolder ID="edt" runat="server">
                                                        <p class="inplace-cntr">
                                                            <input id="tName" type="text" class="in-textbox" runat="server" />
                                                        </p>
                                                        <a href="#" class="icoedit" data-id='<%#: ((DataRowView)Container.DataItem)["ID"]%>'
                                                            data-type='<%#: ((DataRowView)Container.DataItem)["Type"]%>'>edit</a>
                                                        <p class="in-save">
                                                            <input type="submit" class="icosave" data-id='<%#: ((DataRowView)Container.DataItem)["ID"]%>' value="Save" data-cmpnttype='<%#: ((DataRowView)Container.DataItem)["Type"] %>'
                                                                data-type='<%#: ((DataRowView)Container.DataItem)["Type"]%>' data-updatetype="n" />
                                                            <a class='in-cancel' href='#'>Cancel</a>
                                                        </p>
                                                    </asp:PlaceHolder>
                                                </div>
                                                <div class="text">
                                                    <h4>
                                                        <asp:Literal ID="ltlDescription" runat="server" /></h4>
                                                    <asp:PlaceHolder ID="edt2" runat="server">
                                                        <p class="inplace-cntr">
                                                            <input id="tDesc" type="text" class="in-textbox" runat="server" />
                                                        </p>
                                                        <a href="#" class="icoedit" data-id='<%#: ((DataRowView)Container.DataItem)["ID"]%>'
                                                            data-type='<%#: ((DataRowView)Container.DataItem)["Type"]%>'>edit</a>
                                                        <p class="in-save">
                                                            <input type="submit" class="icosave" data-id='<%#: ((DataRowView)Container.DataItem)["ID"]%>' value="Save" data-cmpnttype='<%#: ((DataRowView)Container.DataItem)["Type"] %>'
                                                                data-type='<%#: ((DataRowView)Container.DataItem)["Type"]%>' data-updatetype="d" />
                                                            <a class='in-cancel' href='#'>Cancel</a>
                                                        </p>
                                                    </asp:PlaceHolder>
                                                </div>
                                            </div>
                                            <div class="icon-hold">
                                                <span id="del" runat="server"><a href="#" class="delete" data-cmpntid='<%#: ((DataRowView)Container.DataItem)["ID"]%>'
                                                    data-ccid='<%#: ((DataRowView)Container.DataItem)["ID"]%>' data-cmpnttype='<%#: ((DataRowView)Container.DataItem)["Type"]%>'>delete</a></span>
                                                <span><a href="#" id="show" class="show" data-ccid='<%#: ((DataRowView)Container.DataItem)["ID"]%>'>show</a></span>
                                                <span id="drg" runat="server"><a href="#" class="drag">move</a></span>
                                            </div>
                                            <asp:Literal ID="ltlUnassigned" runat="server" Visible="true"> <h5 class="unassigned">unassigned</h5></asp:Literal>
                                        </div>
                                        <asp:Literal ID="ltlExtraDesc" runat="server"></asp:Literal>
                                    </div>

                                    <asp:Literal ID="ltlNested" runat="server" />
                                </li>
                            </ItemTemplate>
                            <FooterTemplate>
                                </ol>
                            </FooterTemplate>
                        </asp:Repeater>
            </div>
        </div>

        <br />

        <div class="block" id="DivDataLayer"  runat="server">
            <div class="dashboard-hold">
                <h3>Data Layer</h3>
            
                <a href="#new-data" id="newDataItem" class="abbtn fancybox">New Data Element</a><br />
                <div id="new-data" style="width: 640px; padding: 24px; border: 1px solid #ddd; display: none;">
                    <h2 class="headline">New Data Element</h2>
                    <div class="sign-form">
                        <div class="input-hold">

                            <asp:Label ID="Label10" CssClass="sign-label" AssociatedControlID="txtLabel" runat="server">Label</asp:Label>
                            <asp:TextBox CssClass="sign-input" ID="txtLabel" runat="server" Width="200px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvtxtLabel" ForeColor="Red" Text="*" ValidationGroup="DataGroup" ControlToValidate="txtLabel" runat="server" ErrorMessage="* Label is required"></asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ValidationExpression=".*" EnableClientScript="True" ID="RegexDataLabel" ForeColor="Red" ValidationGroup="DataGroup" ControlToValidate="txtLabel" runat="server" ErrorMessage="* Label already in use"></asp:RegularExpressionValidator>
                        </div>

                        <div class="input-hold">

                            <asp:Label ID="Label11" CssClass="sign-label" runat="server" AssociatedControlID="ddlVariable" Text="Variable"></asp:Label>

                            <asp:DropDownList CssClass="sign-select" ID="ddlVariable" runat="server" DataSourceID="SqlDataSource5" DataTextField="Name" DataValueField="ID">
                            </asp:DropDownList>
                            <asp:SqlDataSource ID="SqlDataSource5" ConnectionString="<%$ ConnectionStrings:beelabConnectionString %>" SelectCommand="SELECT ID, Name FROM Variables WHERE ProgramID=(SELECT ProgramID FROM Stages WHERE ID=@StageID)" runat="server">
                                <SelectParameters>
                                    <asp:QueryStringParameter Name="StageID" QueryStringField="ID" Type="Int32" />
                                </SelectParameters>
                            </asp:SqlDataSource>

                            <asp:RequiredFieldValidator ID="rfvddlVariable" ControlToValidate="ddlVariable" InitialValue="Choose" ForeColor="Red" ValidationGroup="DataGroup" runat="server" ErrorMessage="* Variable is required" Text="*"></asp:RequiredFieldValidator>
                        </div>
                        <div class="input-hold">
                            <asp:Button CssClass="sign-submit" ID="Button3" Text="Submit" ValidationGroup="DataGroup" runat="server" OnClick="Button3_Click" />
                        </div>
                    </div>
                    <div class="error">
                        <asp:ValidationSummary ID="ValidationSummary2" runat="server" ValidationGroup="VariableGroup" />
                        <p>&nbsp</p>
                    </div>
                </div>

                        
            </div>

            <asp:GridView ID="gvDataLayer" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" CssClass="dash-col">
                <Columns>
                    <asp:BoundField DataField="Label" HeaderText="Label" SortExpression="Label" />
                    <asp:BoundField DataField="Name" HeaderText="Variable" SortExpression="Name" />
                    <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="EditDataElement.aspx?ID={0}" Text="Edit" />
                    <asp:ButtonField CommandName="Delete" Text="Delete" />
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:beelabConnectionString %>" SelectCommand="SELECT DataElements.ID, Label, Name FROM DataElements JOIN Variables ON Variables.ID=DataElements.VariableID WHERE StageID=@StageID" DeleteCommand="DELETE FROM DataElements WHERE ID=@ID">
                <SelectParameters>
                    <asp:QueryStringParameter Name="StageID" QueryStringField="ID" Type="Int32" />
                </SelectParameters>
                <DeleteParameters>
                    <asp:ControlParameter ControlID="gvDataLayer" Type="Int32" />
                </DeleteParameters>
            </asp:SqlDataSource>
        </div>
    </div>

    <script type="text/javascript">
        <asp:Literal ID="DescriptionsLiteral" runat="server"></asp:Literal>

        $(document).ready(function () {

            $("a[class='logicbtn fancybox']").fancybox();
            $("a[class='abbtn fancybox']").fancybox();
            $('a[href*="EditPresentationElement.aspx"]').fancybox({ 'type': 'iframe', 'width': '765px'});
            $('a[href*="EditVariable.aspx"]').fancybox({ 'type': 'iframe', 'width': '710px'});
            $('a[href*="EditDataElement.aspx"]').fancybox({ 'type': 'iframe', 'width': '705px'});
            $('a[href*="FunctionSettings.aspx"]').fancybox({ 'type': 'iframe', 'width': '705px'});
            <asp:Literal ID="DocumentReadyLiteral"  runat="server"></asp:Literal>

            <asp:Literal ID="HideElementsLiteral" runat="server"></asp:Literal>

            $('#ContentBody_ddlFunction').bind('change', function() { $('#ContentBody_txtFuncDesc').text(functionDescriptions[this.value]); });

            $('a').filter(function(index) { return $(this).text() === "Delete"; }).click(function() { return confirm('Are you sure you want to delete this item?'); } )
            $('a').filter(function(index) { return $(this).text() === "Remove"; }).click(function() { return confirm('Are you sure you want to delete this item?'); } )

            UpdateSaving(0);

            $(".in-textarea").each(function(){
                var tbox = this;
                editors[$(this).closest('li').find('.icosave').attr("data-id")] = CodeMirror(function(elt) {
                    tbox.parentNode.replaceChild(elt, tbox);
                }, {value: tbox.value, smartIndent: true, lineNumbers: false, matchBrackets: true, lineWrapping: true});
            });
        });


    </script>

    <script src='<%: ResolveClientUrl("~/Content/js/jquery-ui-1.10.3.custom.js")%>'></script>
    <script src='<%: ResolveClientUrl("~/Content/js/jquery.mjs.nestedSortable.js")%>'></script>

    <script src='<%: ResolveClientUrl("~/Content/js/tinymce/tinymce.min.js")%>'></script>
    <script>
        function LoadTinyMCE()
        {
            tinyMCE.init({
                selector: 'textarea.tiny-content',
                resize: false,
                valid_elements : '+*[*]',
                toolbar1: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
                toolbar2: "variables_button | presentation_button | addcont | addpost | code preview | forecolor backcolor emoticons",
                plugins: ["code image link lists autolink advlist preview visualblocks insertdatetime table paste directionality nonbreaking visualblocks"],
                    <% if (Request.QueryString["CustomMenus"] == null || Request.QueryString["CustomMenus"].ToString().Equals("false") == false ){%>
                setup: function (editor) {
                    editor.addButton('variables_button', {
                        type: 'menubutton',
                        text: 'Variables',
                        plugins: [ 'code ' ],
                        icon: false,
                        menu: [
                            <asp:Literal ID="VariablesLiteral" runat="server"></asp:Literal>
                ]
                        });
            editor.addButton('presentation_button', {
                type: 'menubutton',
                text: 'Presentation Elements',
                icon: false,
                menu: [
                    <asp:Literal ID="PresentationLiteral" runat="server"></asp:Literal>
            ]
            });
            
            editor.addButton('addcont', {
                type: 'menubutton',
                text: 'Add Controls',
                icon: false,
                menu: [
                    {text: 'Text', onclick: function() {
                        $.fancybox.open({
                            padding : 0,
                            href:'AddHTMLControl.aspx?type=text',
                            type: 'iframe',
                            helpers : { 
                                overlay : {closeClick: false}
                            }
                        });
                    }},
                            
                    {text: 'Button', onclick: function() {
                        $.fancybox.open({
                            padding : 0,
                            href:'AddHTMLControl.aspx?type=button',
                            type: 'iframe',
                            helpers : { 
                                overlay : {closeClick: false}
                            }
                        });
                    }},

                    {text: 'Checkbox', onclick: function() {
                        $.fancybox.open({
                            padding : 0,
                            href:'AddHTMLControl.aspx?type=checkbox',
                            type: 'iframe',
                            helpers : { 
                                overlay : {closeClick: false}
                            }
                        });
                    }},

                    {text: 'Radio', onclick: function() {
                        $.fancybox.open({
                            padding : 0,
                            href:'AddHTMLControl.aspx?type=radio',
                            type: 'iframe',
                            helpers : { 
                                overlay : {closeClick: false}
                            }
                        });
                    }}
                            
                ]
            });

            editor.addButton('addpost', {
                text: 'Add Submit Button',
                icon: false,
                onclick: function() {
                    editor.insertContent('<input type="button" onclick="OnPost();" value="Submit"/>');
                }
            });
            }
            <% } %>
        });
        }

        LoadTinyMCE();
    </script>

    <script>

        function PageInit() {
            // makes the logic layer sortable
            $('.logic-box').nestedSortable({
                doNotClear: true,
                dropOnEmpty: true,
                forcePlaceholderSize: true,
                handle: '.drag',
                helper: 'original',
                items: 'li', //:not(.ui-state-disabled)',
                opacity: .6,
                placeholder: 'placeholder',
                disableNestingClass: 'mjs-nestedSortable-no-nesting',
                errorClass: 'mjs-nestedSortable-error',
                revert: 250,
                //tabSize: 25,
                tolerance: 'pointer', // 'intersect',
                toleranceElement: '> div',
                //maxLevels: 0,
                isTree: true,
                expandOnHover: 500,
                startCollapsed: true,
                activate: updateState,
                deactivate: updateState,
                change: updateState,
                out: updateState,
                over: updateState,
                update: updateState,
                stop: updateState,
                start: updateState,
                attribute: 'data-id'
            });

            var option = '';
            for (i = 0; i < blocks.length; i++) {
                option += '<option value="' + blocks[i] + '">' + blocks[i] + '</option>';
            }
            $('.blocks').append(option);
        }

        PageInit();

        // hide/show the white area of a element
        $(document).on('click', 'a.hide', function (e) {
            e.preventDefault();
            var $this = $(this).toggleClass('show').toggleClass('hide');
            $this.closest('div.logicblock').siblings('ol').toggle();
            $this.closest('div.logicblock').find('div.inplace-edit').show();
            updateVisibility($this.data('ccid'), true);
        });
        $(document).on('click', 'a.show', function (e) {
            e.preventDefault();
            var $this = $(this).toggleClass('show').toggleClass('hide');
            $this.closest('div.logicblock').siblings('ol').toggle();
            $this.closest('div.logicblock').find('div.loglogic').hide();
            updateVisibility($this.data('ccid'), false);
        });

        function updateVisibility(id, visible){
            var url = '<%:ResolveClientUrl("~/Svc/BeeSvc.asmx/SetVisibility")%>';
            UpdateSaving(1);
            $.ajax({
                async: true,
                type: 'POST',
                url: url,
                data: { ID: id, isVisible: visible }
            }).done(function () {
                UpdateSaving(-1);
            }).fail(function () {
                UpdateSaving(-1);
                alert('Error occured while saving visibility');
            });
        }


        function updateState(event, ui) {
            // when an element's place changed
            // display unassigned if outside the workarea
            if (event.type == 'sortstop') {
                var $li = $(event.toElement).closest('li');
                var $ol = $li.parent();
                var uMsg = '<h5 class="unassigned">unassigned</h5>';

                var $lblock = $ol.siblings('div.logicblock');

                if ($li.data('type').toLowerCase() != "block") {
                    if ($lblock.length) {
                        var $ublock = $li.find('> div.logicblock:first').removeClass('unassign');
                        $ublock.find('h5.unassigned').remove().end().find('div.headblock').removeClass('unassignhead');
                    } else {
                        var $ublock = $li.find('> div.logicblock:first').addClass('unassign');
                        var $unassignedMsg = $ublock.find('h5.unassigned');
                        if (!$unassignedMsg.length) {
                            $unassignedMsg = $(uMsg);
                        }
                        $ublock.find('div.headblock').addClass('unassignhead').end().find('div.icon-hold').after($unassignedMsg);
                    }
                }

                SaveOrder();
            }
        }

        //In place editing buttons / disable links
        $(document).on('click', 'a[href="#"]', function (e) {
            e.preventDefault();
        });

        function SaveOrder() {
            var url = '<%:ResolveClientUrl("~/Svc/BeeSvc.asmx/SubmitLogic")%>';
            var list = $('ol.ui-sortable:first').nestedSortable('serialize');
            UpdateSaving(1);
            $.ajax({
                async: true,
                type: 'POST',
                url: url,
                data: { list: list }
            }).done(function () {
                //alert('Logic layer saved successfully.');
                UpdateSaving(-1);
            }).fail(function () {
                UpdateSaving(-1);
                alert('Error occured while saving the data');
            });
        }

        // deletes the element from db
        $(document).on('click', 'a.delete', function (e) {
            if (!confirm("Are you sure you would like to delete this element?")){
                return false;
            }

            var url = '<%:ResolveClientUrl("~/Svc/BeeSvc.asmx/DeleteElement")%>';
            var $this = $(this);

            UpdateSaving(1);

            var name = $this.closest('.headblock').find('.inplace-edit').text().replace('(Block)','').trim();

            BlocksRE.compile(BlocksRE.source.replace("|" + name +"$", ""));

            var cmpntid = $this.data('cmpntid');
            $.ajax({
                async: true,
                type: 'POST',
                url: url,
                data: { ID: cmpntid }
            }).done(function () {
                $this.closest('li').remove();
                UpdateSaving(-1);
            }).fail(function () {
                UpdateSaving(-1);
            });
        });

        // hides inplace edit form for the chosen field
        $(document).on('click', 'a.in-cancel', function (e) {
            e.preventDefault();
            var $this = $(this);
            var updateType = $this.siblings('input').data('updatetype');
            var isTArea = $this.parent().hasClass('ico-texthold');
            if (isTArea) {
                var $clsr = $this.closest('div.inplace-cntr').hide();
                var txt = $clsr.siblings('.inplace-edit').show().find('p').text().trim().replace(/<br>/g,"\n");
                if ($(this).closest('li').data("type") == "Code"){
                    editors[$clsr.find('.icosave').attr("data-id")].setValue(txt);
                }
                $clsr.siblings('div.inplace-edit').show();
            } else {
                var $clsr = $this.closest('p.in-save').hide().siblings('p.inplace-cntr').hide();
                if (updateType == 'n') {
                    $clsr.find('input').val($clsr.siblings('h2').show().clone().children().remove().end().text().trim());
                } else if (updateType == 'd') {
                    $clsr.find('input').val($clsr.siblings('h4').show().clone().children().remove().end().text().trim());
                }
                $clsr.siblings('h2, h4, a.icoedit').show();
            }
        });

        // display inplace edit form for the chosen field
        $(document).on('click', 'a.icoedit', function (e) {
            e.preventDefault();
            var $this = $(this);
            var isTArea = $this.parent().hasClass('ico-texthold');
            var datatype = $this.data('type').toLowerCase();
            if (isTArea) {
                $this.closest('div.inplace-edit').hide().siblings('div.inplace-cntr').show();
                if (datatype == "code"){
                    $this.closest(".logicblock").find(".inplace-cntr").find(".CodeMirror").width($this.closest(".logicblock").width()-120);
                    editors[$this.data('id')].refresh();
                }
            } else {
                $this.hide().siblings('h2, h4').hide().siblings('p.inplace-cntr, p.in-save').show();
            }
        });

        // saves data into db [inplace editing]
        $(document).on('click', 'input.icosave', function (e) {
            e.preventDefault();
            var $this = $(this);
            var isTArea = $this.parent().hasClass('ico-texthold');

            UpdateSaving(1);

            var datatype = $this.data('type');
            var url = '<%:ResolveClientUrl("~/Svc/BeeSvc.asmx/UpdateData")%>', data = '';

            var id = $this.data('id');
            var name = '', description = '', extraDesc = '',
                updateType = $this.data('updatetype'), cmpnttype = $this.data('cmpnttype');

            if ((cmpnttype == 'Block' || cmpnttype == '1') && updateType == 'n')
            {
                var t = /^[a-zA-Z_][0-9a-zA-Z_]*$/;
                var prevName = $this.closest('.text').find('.inplace-edit').text().replace('(Block)','').trim();

                if (t.test($this.closest('p.in-save').siblings('p.inplace-cntr').find('input').val().trim()) == false)
                {
                    alert('Name must be a valid JS function name');
                    return;
                }
                if ($this.closest('p.in-save').siblings('p.inplace-cntr').find('input').val().trim() != prevName && BlocksRE.test($this.closest('p.in-save').siblings('p.inplace-cntr').find('input').val().trim()) == false) // TODO Check if name was changed at all
                {
                    alert('Name already in use');
                    return;
                }
                
                BlocksRE.compile(BlocksRE.source.replace("|" + prevName +"$", "|" + $this.closest('p.in-save').siblings('p.inplace-cntr').find('input').val().trim() +"$"));
            }

            if (isTArea) {
                if (cmpnttype == 'Call' || cmpnttype == '2') {
                    extraDesc = $this.closest('div.inplace-cntr').find('p > select').val().trim();
                }
                else {
                    extraDesc = editors[id].getValue(); //$this.closest('div.inplace-cntr').find('p > textarea').val().trim();
                    if (extraDesc == null || extraDesc == '') {
                        extraDesc = '//';
                    }
                }
            } else {
                if (updateType == 'n') {
                    name = $this.closest('p.in-save').siblings('p.inplace-cntr').find('input').val().trim();
                } else if (updateType == 'd') {
                    description = $this.closest('p.in-save').siblings('p.inplace-cntr').find('input').val().trim();
                }
            }
            data = { Name: name, Description: description, Content: extraDesc, ID: id, updateType: updateType };

            if (url && data && id && updateType && cmpnttype && (name || description || extraDesc)) {
                $.ajax({
                    async: true,
                    type: 'POST',
                    url: url,
                    data: data
                }).done(function () {
                    if (isTArea) {
                        $this.closest('div.inplace-cntr').hide().siblings('.inplace-edit').show().find('p').html(extraDesc.replace(/\n/g,"<br/>"));
                    } else {
                        if (updateType == 'n') {
                            $this.closest('p.in-save').hide().siblings('p.inplace-cntr').hide().siblings('h2, a.icoedit')
                                .show().html(name + '<span>(' + datatype + ')</span>');
                        } else if (updateType == 'd') {
                            $this.closest('p.in-save').hide().siblings('p.inplace-cntr').hide().siblings('h4, a.icoedit')
                                .show().html(description + '<span>(' + datatype + ')</span>');
                        }
                    }

                    UpdateSaving(-1);
                }).fail(function () {
                    alert('Error occured while saving information!');
                    UpdateSaving(-1);
                });
            }

        });

        // get querystring value by providing the key name
        function getParameterByName(name) {
            name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
                results = regex.exec(location.search);
            return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
        }
    </script>

</asp:Content>
